<?php 
//定义接口
interface User
{
    public function getDiscount();
    public function getUserType();
}
//VIP用户 接口实现
class VipUser implements User
{
    // VIP 用户折扣系数
    private $discount = 0.8;
    public function getDiscount()
    {
        return $this->discount;
    }
    public function getUserType()
    {
        return "VIP用户";
    }
}
//普通用户 接口实现
class GeneralUser implements User
{
    // VIP 用户折扣系数
    private $discount = 0.95;
    public function getDiscount()
    {
        return $this->discount;
    }
    public function getUserType()
    {
        return "普通用户";
    }
}
class Goods
{
    public $price = 100;
    public $vc;
    //定义 User 接口类型参数，这时并不知道是什么用户
    public function run(User $vc)
    {
        $this->vc = $vc;
        $discount = $this->vc->getDiscount();
        $usertype = $this->vc->getUserType();
        echo $usertype."商品价格：".$this->price*$discount;
    }
}
$display = new Goods();
$display ->run(new VipUser); //可以是更多其他用户类型
echo "<br>";
$display ->run(new GeneralUser); //看看普通用户什么情况;
